﻿using University.Workshop.DataAccess;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using University.Workshop.Model;
using System.Collections.ObjectModel;
using University.Workshop.Business;

namespace University.Workshop.Tests
{
    
    
    /// <summary>
    ///This is a test class for OrderDataAccessTest and is intended
    ///to contain all OrderDataAccessTest Unit Tests
    ///</summary>
    [TestClass()]
    public class OrderDataAccessTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for AddNewOrder
        ///</summary>
        [TestMethod()]
        public void AddNewOrderTest()
        {
            string firstName = "Pedro"; // TODO: Initialize to an appropriate value
            string lastName = "Suarez"; // TODO: Initialize to an appropriate value
            char gender = 'M'; // TODO: Initialize to an appropriate value
            Random rand = new Random();
            DateTime birthday = DateTime.Now.AddYears(-18); // TODO: Initialize to an appropriate value
            string email = "pedro" + rand.Next(400) + "@gmail.com"; // TODO: Initialize to an appropriate value
            string password = "qwert1"; // TODO: Initialize to an appropriate value
            string rePassword = "qwert1"; // TODO: Initialize to an appropriate value
            string department = "Cochabamba"; // TODO: Initialize to an appropriate value
            string city = "Cercado"; // TODO: Initialize to an appropriate value
            string movilephone = "" + rand.Next(79999999); // TODO: Initialize to an appropriate value
            string phone = "" + rand.Next(4999999); // TODO: Initialize to an appropriate value
            UserRegistrationManager.RegisterUser(firstName, lastName, gender, birthday, email, password, rePassword, department, city, movilephone, phone);
            Collection<Product> products = new Collection<Product>();
            products.Add(ProductRegistrationManager.RegisterNewProduct("computadoras portatiles", "5234", "fafawfwef awefwfwefawfwef afwefawefawf fasfsafsaffsf", "Electronics", false, "Bolivianos", 1, "1"));
            products.Add(ProductRegistrationManager.RegisterNewProduct("deportivos americanos", "334", "fafawfwef awefwfwefawfwef afwefawefawf fasfsafsaffsf", "Fashion", false, "Dollars", 1, "1"));
            long buyerId = 1; // TODO: Initialize to an appropriate value
            long expected = -1; // TODO: Initialize to an appropriate value
            long actual;
            actual = OrderDataAccess.AddNewOrder(products, buyerId);
            Assert.AreNotEqual(expected, actual);
        }

        /// <summary>
        ///A test for CompleteOrder
        ///</summary>
        [TestMethod()]
        public void CompleteOrderTest()
        {
            string firstName = "Pedro"; // TODO: Initialize to an appropriate value
            string lastName = "Suarez"; // TODO: Initialize to an appropriate value
            char gender = 'M'; // TODO: Initialize to an appropriate value
            Random rand = new Random();
            DateTime birthday = DateTime.Now.AddYears(-18); // TODO: Initialize to an appropriate value
            string email = "pedro" + rand.Next(400) + "@gmail.com"; // TODO: Initialize to an appropriate value
            string password = "qwert1"; // TODO: Initialize to an appropriate value
            string rePassword = "qwert1"; // TODO: Initialize to an appropriate value
            string department = "Cochabamba"; // TODO: Initialize to an appropriate value
            string city = "Cercado"; // TODO: Initialize to an appropriate value
            string movilephone = "" + rand.Next(79999999); // TODO: Initialize to an appropriate value
            string phone = "" + rand.Next(4999999); // TODO: Initialize to an appropriate value
            UserRegistrationManager.RegisterUser(firstName, lastName, gender, birthday, email, password, rePassword, department, city, movilephone, phone);
            Collection<Product> products = new Collection<Product>();
            products.Add(ProductRegistrationManager.RegisterNewProduct("computadoras portatiles", "5234", "fafawfwef awefwfwefawfwef afwefawefawf fasfsafsaffsf", "Electronics", false, "Bolivianos", 1, "1"));
            products.Add(ProductRegistrationManager.RegisterNewProduct("deportivos americanos", "334", "fafawfwef awefwfwefawfwef afwefawefawf fasfsafsaffsf", "Fashion", false, "Dollars", 1, "1"));
            long buyerId = 1; // TODO: Initialize to an appropriate value
            long orderId = OrderDataAccess.AddNewOrder(products, buyerId);
            OrderDataAccess.CompleteOrder(orderId);
        }

        /// <summary>
        ///A test for GetNewOrderNumber
        ///</summary>
        [TestMethod()]
        [DeploymentItem("University.Workshop.DataAccess.dll")]
        public void GetNewOrderNumberTest()
        {
            long expected = 0; // TODO: Initialize to an appropriate value
            long actual;
            actual = OrderDataAccess_Accessor.GetNewOrderNumber();
            Assert.AreNotEqual(expected, actual);
        }

        /// <summary>
        ///A test for GetProductIdByOrderId
        ///</summary>
        [TestMethod()]
        public void GetProductIdByOrderIdTest()
        {
            AddNewOrderTest();
            OrderDataAccess.GetProductIdByOrderId(1);
        }

        /// <summary>
        ///A test for GetMostBought
        ///</summary>
        [TestMethod()]
        public void GetMostBoughtTest()
        {
            string firstName = "Pedro"; // TODO: Initialize to an appropriate value
            string lastName = "Suarez"; // TODO: Initialize to an appropriate value
            char gender = 'M'; // TODO: Initialize to an appropriate value
            Random rand = new Random();
            DateTime birthday = DateTime.Now.AddYears(-18); // TODO: Initialize to an appropriate value
            string email = "pedro" + rand.Next(400) + "@gmail.com"; // TODO: Initialize to an appropriate value
            string password = "qwert1"; // TODO: Initialize to an appropriate value
            string rePassword = "qwert1"; // TODO: Initialize to an appropriate value
            string department = "Cochabamba"; // TODO: Initialize to an appropriate value
            string city = "Cercado"; // TODO: Initialize to an appropriate value
            string movilephone = "" + rand.Next(79999999); // TODO: Initialize to an appropriate value
            string phone = "" + rand.Next(4999999); // TODO: Initialize to an appropriate value
            UserRegistrationManager.RegisterUser(firstName, lastName, gender, birthday, email, password, rePassword, department, city, movilephone, phone);
            Collection<Product> products = new Collection<Product>();
            User user = UserDataAccess.GetUserByEmail(email);
            Product prod = ProductRegistrationManager.RegisterNewProduct("computadoras portatiles", "5234", "fafawfwef awefwfwefawfwef afwefawefawf fasfsafsaffsf", "Electronics", false, "Dollars", 1, "1");
            products.Add(ProductRegistrationManager.RegisterNewProduct("computadoras portatiles", "5234", "fafawfwef awefwfwefawfwef afwefawefawf fasfsafsaffsf", "Electronics", false, "Dollars", 1, "1"));
            long id = OrderDataAccess.AddNewOrder(products,user.Id);
            OrderDataAccess.CompleteOrder(id);
            products.Clear();
            products.Add(prod);
            id = OrderDataAccess.AddNewOrder(products, user.Id);
            OrderDataAccess.CompleteOrder(id);
            long productId = prod.ProductId; // TODO: Initialize to an appropriate value
            Collection<long> expected = null; // TODO: Initialize to an appropriate value
            Collection<long> actual;
            actual = OrderDataAccess.GetMostBought(productId);
            Assert.AreNotEqual(expected, actual);
        }

        [TestMethod()]
        public void GetMostBoughtTestFail()
        {
            string firstName = "Pedro"; // TODO: Initialize to an appropriate value
            string lastName = "Suarez"; // TODO: Initialize to an appropriate value
            char gender = 'M'; // TODO: Initialize to an appropriate value
            Random rand = new Random();
            DateTime birthday = DateTime.Now.AddYears(-18); // TODO: Initialize to an appropriate value
            string email = "pedro" + rand.Next(400) + "@gmail.com"; // TODO: Initialize to an appropriate value
            string password = "qwert1"; // TODO: Initialize to an appropriate value
            string rePassword = "qwert1"; // TODO: Initialize to an appropriate value
            string department = "Cochabamba"; // TODO: Initialize to an appropriate value
            string city = "Cercado"; // TODO: Initialize to an appropriate value
            string movilephone = "" + rand.Next(79999999); // TODO: Initialize to an appropriate value
            string phone = "" + rand.Next(4999999); // TODO: Initialize to an appropriate value
            UserRegistrationManager.RegisterUser(firstName, lastName, gender, birthday, email, password, rePassword, department, city, movilephone, phone);
            ProductRegistrationManager.RegisterNewProduct("computadoras portatiles", "5234", "fafawfwef awefwfwefawfwef afwefawefawf fasfsafsaffsf", "Electronics", false, "Dollars", 1, "1");
            long productId = -1; // TODO: Initialize to an appropriate value
            Collection<long> expected = null; // TODO: Initialize to an appropriate value
            Collection<long> actual;
            actual = OrderDataAccess.GetMostBought(productId);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for GetMostBoughtByViewed
        ///</summary>
        [TestMethod()]
        public void GetMostBoughtByViewedTest()
        {
            string firstName = "Pedro"; // TODO: Initialize to an appropriate value
            string lastName = "Suarez"; // TODO: Initialize to an appropriate value
            char gender = 'M'; // TODO: Initialize to an appropriate value
            Random rand = new Random();
            DateTime birthday = DateTime.Now.AddYears(-18); // TODO: Initialize to an appropriate value
            string email = "pedro" + rand.Next(400) + "@gmail.com"; // TODO: Initialize to an appropriate value
            string password = "qwert1"; // TODO: Initialize to an appropriate value
            string rePassword = "qwert1"; // TODO: Initialize to an appropriate value
            string department = "Cochabamba"; // TODO: Initialize to an appropriate value
            string city = "Cercado"; // TODO: Initialize to an appropriate value
            string movilephone = "" + rand.Next(79999999); // TODO: Initialize to an appropriate value
            string phone = "" + rand.Next(4999999); // TODO: Initialize to an appropriate value
            UserRegistrationManager.RegisterUser(firstName, lastName, gender, birthday, email, password, rePassword, department, city, movilephone, phone);
            Collection<Product> products = new Collection<Product>();
            Product prod = ProductRegistrationManager.RegisterNewProduct("computadoras portatiles", "5234", "fafawfwef awefwfwefawfwef afwefawefawf fasfsafsaffsf", "Electronics", false, "Dollars", 1, "1");
            products.Add(ProductRegistrationManager.RegisterNewProduct("computadoras portatiles", "5234", "fafawfwef awefwfwefawfwef afwefawefawf fasfsafsaffsf", "Electronics", false, "Dollars", 1, "1"));
            products.Add(prod);
            long id = OrderDataAccess.AddNewOrder(products, 1);
            OrderDataAccess.CompleteOrder(id);
            long productId = prod.ProductId; // TODO: Initialize to an appropriate value
            Collection<long> expected = null; // TODO: Initialize to an appropriate value
            Collection<long> actual;
            ViewsDataAccess.InsertView("1", productId.ToString(), DateTime.Now);
            actual = OrderDataAccess.GetMostBoughtByViewed(productId);
            Assert.AreNotEqual(expected, actual);
        }

        /// <summary>
        ///A test for ProductByIdOfOrder
        ///</summary>
        [TestMethod()]
        public void ProductByIdOfOrderTest()
        {
            string firstName = "Pedro"; // TODO: Initialize to an appropriate value
            string lastName = "Suarez"; // TODO: Initialize to an appropriate value
            char gender = 'M'; // TODO: Initialize to an appropriate value
            Random rand = new Random();
            DateTime birthday = DateTime.Now.AddYears(-18); // TODO: Initialize to an appropriate value
            string email = "pedro" + rand.Next(400) + "@gmail.com"; // TODO: Initialize to an appropriate value
            string password = "qwert1"; // TODO: Initialize to an appropriate value
            string rePassword = "qwert1"; // TODO: Initialize to an appropriate value
            string department = "Cochabamba"; // TODO: Initialize to an appropriate value
            string city = "Cercado"; // TODO: Initialize to an appropriate value
            string movilephone = "" + rand.Next(79999999); // TODO: Initialize to an appropriate value
            string phone = "" + rand.Next(4999999); // TODO: Initialize to an appropriate value
            UserRegistrationManager.RegisterUser(firstName, lastName, gender, birthday, email, password, rePassword, department, city, movilephone, phone);
            Collection<Product> products = new Collection<Product>();
            long buyerId = UserDataAccess.GetUserByEmail(email).Id;
            Product prod1 = ProductRegistrationManager.RegisterNewProduct("computadoras portatiles", "5234", "fafawfwef awefwfwefawfwef afwefawefawf fasfsafsaffsf", "Electronics", false, "Bolivianos", 1, "1");
            products.Add(prod1);
            long ordId=OrderDataAccess.AddNewOrder(products, buyerId);
            OrderDataAccess.CompleteOrder(ordId);
            Collection<Order> res;
            res = OrderDataAccess.GetOrdersByBuyerId(buyerId);
            long orderId = res[0].Id; // TODO: Initialize to an appropriate value 
            Product actual = OrderDataAccess.ProductByIdOfOrder(orderId);
            Assert.AreEqual(res[0].ProductId, actual.ProductId);
        }

        /// <summary>
        ///A test for GetOrdersByBuyerId
        ///</summary>
        [TestMethod()]
        public void GetOrdersByBuyerIdTest()
        {
            string firstName = "Pedro"; // TODO: Initialize to an appropriate value
            string lastName = "Suarez"; // TODO: Initialize to an appropriate value
            char gender = 'M'; // TODO: Initialize to an appropriate value
            Random rand = new Random();
            DateTime birthday = DateTime.Now.AddYears(-18); // TODO: Initialize to an appropriate value
            string email = "pedro" + rand.Next(400) + "@gmail.com"; // TODO: Initialize to an appropriate value
            string password = "qwert1"; // TODO: Initialize to an appropriate value
            string rePassword = "qwert1"; // TODO: Initialize to an appropriate value
            string department = "Cochabamba"; // TODO: Initialize to an appropriate value
            string city = "Cercado"; // TODO: Initialize to an appropriate value
            string movilephone = "" + rand.Next(79999999); // TODO: Initialize to an appropriate value
            string phone = "" + rand.Next(4999999); // TODO: Initialize to an appropriate value
            UserRegistrationManager.RegisterUser(firstName, lastName, gender, birthday, email, password, rePassword, department, city, movilephone, phone);
            Collection<Product> products = new Collection<Product>();
            long buyerId = UserDataAccess.GetUserByEmail(email).Id;
            Product prod1 = ProductRegistrationManager.RegisterNewProduct("computadoras portatiles", "5234", "fafawfwef awefwfwefawfwef afwefawefawf fasfsafsaffsf", "Electronics", false, "Bolivianos", buyerId, "1");
            Product prod2 = ProductRegistrationManager.RegisterNewProduct("deportivos americanos", "334", "fafawfwef awefwfwefawfwef afwefawefawf fasfsafsaffsf", "Fashion", false, "Dollars", buyerId, "1");
            products.Add(prod1);
            products.Add(prod2);
            long ordId=OrderDataAccess.AddNewOrder(products, buyerId);
            OrderDataAccess.CompleteOrder(ordId);
            Collection<Order> actual;
            actual = OrderDataAccess.GetOrdersByBuyerId(buyerId);
            Assert.AreEqual(products[0].ProductId, actual[0].ProductId);
        }

        /// <summary>
        ///A test for ProductByOrderId
        ///</summary>
        [TestMethod()]
        public void ProductByOrderIdTest()
        {
            string firstName = "Pedro"; // TODO: Initialize to an appropriate value
            string lastName = "Suarez"; // TODO: Initialize to an appropriate value
            char gender = 'M'; // TODO: Initialize to an appropriate value
            Random rand = new Random();
            DateTime birthday = DateTime.Now.AddYears(-18); // TODO: Initialize to an appropriate value
            string email = "pedro" + rand.Next(400) + "@gmail.com"; // TODO: Initialize to an appropriate value
            string password = "qwert1"; // TODO: Initialize to an appropriate value
            string rePassword = "qwert1"; // TODO: Initialize to an appropriate value
            string department = "Cochabamba"; // TODO: Initialize to an appropriate value
            string city = "Cercado"; // TODO: Initialize to an appropriate value
            string movilephone = "" + rand.Next(79999999); // TODO: Initialize to an appropriate value
            string phone = "" + rand.Next(4999999); // TODO: Initialize to an appropriate value
            UserRegistrationManager.RegisterUser(firstName, lastName, gender, birthday, email, password, rePassword, department, city, movilephone, phone);
            Collection<Product> products = new Collection<Product>();
            long buyerId = UserDataAccess.GetUserByEmail(email).Id;
            Product prod1 = ProductRegistrationManager.RegisterNewProduct("computadoras portatiles", "5234", "fafawfwef awefwfwefawfwef afwefawefawf fasfsafsaffsf", "Electronics", false, "Bolivianos", buyerId, "1");
            Product prod2 = ProductRegistrationManager.RegisterNewProduct("deportivos americanos", "334", "fafawfwef awefwfwefawfwef afwefawefawf fasfsafsaffsf", "Fashion", false, "Dollars", buyerId, "1");
            products.Add(prod1);
            products.Add(prod2);
            long ordId = OrderDataAccess.AddNewOrder(products, buyerId);
            Product expected = null; // TODO: Initialize to an appropriate value
            Product actual;
            actual = OrderDataAccess.ProductByOrderId(ordId);
            Assert.AreNotEqual(expected, actual);
        }

        /// <summary>
        ///A test for GetFrequentlyBoughtTogether
        ///</summary>
        [TestMethod()]
        public void GetFrequentlyBoughtTogetherTest()
        {
            string firstName = "Pedro"; // TODO: Initialize to an appropriate value
            string lastName = "Suarez"; // TODO: Initialize to an appropriate value
            char gender = 'M'; // TODO: Initialize to an appropriate value
            Random rand = new Random();
            DateTime birthday = DateTime.Now.AddYears(-18); // TODO: Initialize to an appropriate value
            string email = "pedro" + rand.Next(400) + "@gmail.com"; // TODO: Initialize to an appropriate value
            string password = "qwert1"; // TODO: Initialize to an appropriate value
            string rePassword = "qwert1"; // TODO: Initialize to an appropriate value
            string department = "Cochabamba"; // TODO: Initialize to an appropriate value
            string city = "Cercado"; // TODO: Initialize to an appropriate value
            string movilephone = "" + rand.Next(79999999); // TODO: Initialize to an appropriate value
            string phone = "" + rand.Next(4999999); // TODO: Initialize to an appropriate value
            UserRegistrationManager.RegisterUser(firstName, lastName, gender, birthday, email, password, rePassword, department, city, movilephone, phone);
            Collection<Product> products = new Collection<Product>();
            Product prod = ProductRegistrationManager.RegisterNewProduct("computadoras portatiles", "5234", "fafawfwef awefwfwefawfwef afwefawefawf fasfsafsaffsf", "Electronics", false, "Dollars", 1, "1");
            products.Add(ProductRegistrationManager.RegisterNewProduct("computadoras portatiles", "5234", "fafawfwef awefwfwefawfwef afwefawefawf fasfsafsaffsf", "Electronics", false, "Dollars", 1, "1"));
            products.Add(prod);
            long id = OrderDataAccess.AddNewOrder(products, 1);
            OrderDataAccess.CompleteOrder(id);
            long productId = prod.ProductId; // TODO: Initialize to an appropriate value
            Collection<long> expected = null; // TODO: Initialize to an appropriate value
            Collection<long> actual;
            actual = OrderDataAccess.GetMostBought(productId);
            Assert.AreNotEqual(expected, actual);
        }
    }
}
